//
//  MsZzfqDetailSubmitOrderVC.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/12/3.
//  Copyright © 2018 tzhg. All rights reserved.
//
/** 秒杀确认订单 */
#import "MsZzfqDetailSubmitOrderVC.h"
#import "ConfirmOrderTableViewCell.h"
#import "InvoiceViewController.h"
#import "PayViewController.h"
#import "UIViewController+HBD.h"


@interface MsZzfqDetailSubmitOrderVC ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *mainTable;

@property (nonatomic, strong) NSArray *array;

@property (nonatomic, strong) UIView *headView;

@property (nonatomic, strong) UIView *commitView;

@end

@implementation MsZzfqDetailSubmitOrderVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationItems];
    self.view.backgroundColor = [UIColor whiteColor];
    self.hbd_barTintColor = [UIColor whiteColor];
    
    _array = @[@{@"title" : @"思威数码专营店",
                 @"icon" : @"",
                 @"product" : @[@{@"productImage" : @"",
                                  @"productName" : @"新鲜夏季酸草莓水果1000g 烘焙蛋糕装饰冰饮专用",
                                  @"productPrice" : @"¥98.00"}],
                 @"content" : @[@{@"配送方式" : @"快递 免邮"},
                                @{@"发票类型" : @"电子发票"}, @{@"发票抬头" : @"个人"}]}];
    
    [self.view addSubview:self.mainTable];
    [self.view addSubview:self.commitView];
}


- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    /** title */
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    titleLabel.text = @"确认订单";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = FONT_EIGHTEEN;
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    self.navigationItem.titleView = titleLabel;
    
}

- (void)backAction:(UIBarButtonItem *)item {
    
    [self.navigationController popViewControllerAnimated:YES];
}


/** 创建tableview  */

- (UITableView *)mainTable {
    
    if (!_mainTable) {
        _mainTable = [[UITableView alloc] initWithFrame:CGRectMake(0, Hn, SCREEN_WIDTH, SCREEN_HEIGHT - Hn - 44) style:UITableViewStylePlain];
        _mainTable.delegate = self;
        _mainTable.dataSource = self;
        _mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_mainTable registerClass:[ConfirmOrderTableViewCell class] forCellReuseIdentifier:@"ConfirmOrderTableViewCell"];
        _mainTable.tableHeaderView = self.headView;
    }
    return _mainTable;
}

/** 表头视图 */

- (UIView *)headView {
    
    if (!_headView) {
        _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        _headView.backgroundColor = [UIColor whiteColor];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 200, 30)];
        titleLabel.textColor = [UIColor colorWithHex:0x333333];
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.text = @"收货人：哆啦A梦";
        [_headView addSubview:titleLabel];
        
        UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 110, 10, 100, 30)];
        phoneLabel.textColor = [UIColor colorWithHex:0x333333];
        phoneLabel.font = [UIFont systemFontOfSize:14];
        phoneLabel.textAlignment = NSTextAlignmentRight;
        phoneLabel.text = @"19987360890";
        [_headView addSubview:phoneLabel];
        
        
        UILabel *adressLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, SCREEN_WIDTH - 20, 30)];
        adressLabel.textColor = [UIColor colorWithHex:0x333333];
        adressLabel.font = [UIFont systemFontOfSize:14];
        adressLabel.text = @"收货地址：云南省昆明市盘龙区白云路";
        [_headView addSubview:adressLabel];
        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 90, SCREEN_WIDTH, 10)];
        lineView.backgroundColor = [UIColor colorWithHex:0xf6f6f6];
        [_headView addSubview:lineView];
    }
    return _headView;
}





/** 表尾视图 */

- (UIView *)commitView {
    
    if (!_commitView) {
        _commitView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 44, SCREEN_WIDTH, 44)];
        _commitView.backgroundColor = [UIColor whiteColor];
        
        UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        commitBtn.frame = CGRectMake(SCREEN_WIDTH - 110, 0, 110, 44);
        [commitBtn setTitle:@"提交" forState:UIControlStateNormal];
        commitBtn.backgroundColor = [UIColor colorWithHex:0xFF9E05];
        [commitBtn addTarget:self action:@selector(commitAction) forControlEvents:UIControlEventTouchUpInside];
        [_commitView addSubview:commitBtn];
        
        UILabel *moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(commitBtn.frame) - 200, 0, 200, 44)];
        moneyLabel.text = @"合计：￥98.00元";
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        moneyLabel.textColor = COLOR_ORG;
        [_commitView addSubview:moneyLabel];
    }
    return _commitView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dic = _array[0];
    return 95 * [dic[@"product"] count] + 40 * [dic[@"content"] count] + 90;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ConfirmOrderTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ConfirmOrderTableViewCell"];
    cell.typeAry = _array[0][@"content"];
    cell.productAry = _array[0][@"product"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.invoiceClick = ^{
        InvoiceViewController *vc = [InvoiceViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    };
    return cell;
}



- (void)commitAction {
    
    PayViewController *vc = [PayViewController new];
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
